#!/usr/bin/env python
# coding: utf-8

# In[7]:


"""使用 While循环实现输出2-3+4-5+6...+100的和"""

i = 2
n = 0
# 初始化数字和总和

while i <= 100:  
    # 对2~100的整数求和：偶数相加，奇数相减
    if i % 2 == 0:
        n += i
    elif i % 2 == 1:
        n -= i
    i += 1

print("总和为 %s." % n)


# In[1]:


print(sum([i for i in range(2,101,2)]) - sum([j for j in range(3,100,2)] ))
# 对2~100的整数直接求和：偶数相加，奇数相减


# In[ ]:




